TConfig Classes
tConfig allows you to write code which is called on within various parts of the game. Here's a list of all of the methods that you can create for each class. This is being updated for the new version of tConfig. Anything that is crossed out has not been implemented. ModWorld Networking *void NetReceive(int msg, BinaryReader reader) - Called when a net message is received for this ModWorld class. *void NetSend(int msg, BinaryWriter writer) - Called when a net message needs to be sent. *void PlayerConnected(int playerID) - Called on the server when a player connects *void SyncPlayers() - Called on the server when a player joins, and periodically afterwards. To send a message with NetSend, you would call NetMessage.SendData with 100 as the msgType, and the modIndex & your own message ID passed as parameters. Another way to send a message, much more easily, is using the new NetMessage.SendModData() method. You can pass in basic data types and it will automatically write them into the networking stream appropriately. The method signature is: void SendModData(int modIndex, int msgID, int remoteClient = -1, int ignoreClient = -1, params object[] parameters) The Deathmatch PVP mod available here is a great example of using these networking capabilities. Global Classes ModWorld and ModPlayer classes are defined in 'Global\World.cs' and 'Global\Player.cs' respectively. *void Save(BinaryWriter writer) - Save data to the player or world. *void Load(BinaryReader reader, int version) - Load data associated with the player or world. *void Initialize() - Called when the world or player is loaded. It is HIGHLY recommended that you write this method for resetting variables. If you don't, then switching to a different world or player could result in unexpected behavior. ModWorld *void PostDraw(SpriteBatch spriteBatch) - Called every tick, after the default drawing method *void PreDrawInterface(SpriteBatch spriteBatch) - called before interface is drawn *bool PreHitWire(int x, int y) - called when HitWire() is called. Return true to execute normal hitwire function, false otherwise. *void UpdateWorld() - Called every tick at the end of default UpdateWorld, before custom tile update ModPlayer *void UpdatePlayer(Player player) - Called every 'tick' *void CreatePlayer(Player player) - Called when a Player instance is created. This is where it sets the player's default starting items. *void PreUpdatePlayer(Player player) - Called every 'tick', before the effects from items and buffs are applied. ModGeneric *Defined in Global\Generic.cs *void OnLoad() - Called after mods and content are loaded. Can be useful for loading texture packs. *void UpdateSpawn() *Does not have initialize/save/load methods Interfaces Interfaces are defined through a class called InterfaceObj. It can include item slots, and text-based buttons. Call-back methods are defined using an interface called Interfaceable. Currently you can only bring up custom interfaces through NPCs or Tiles. Interfaceable *bool DropSlot(int slotNum) - Called when the interface is closed - return true if you want the item in the slot to be dropped, false otherwise *void ButtonClicked(int buttonNum) - Perform an action when the specified button is clicked on. This will be called if the button is defined to be clickable. *bool CanPlaceSlot(int slotNum, Item mouseItem) - return true if you want to let the player place / pick up an item in the specified slot. mouseItem is the item currently held by the mouse. *void PlaceSlot(int slotNum) - Perform some action after an item has been placed or taken from the specified slot Not part of the interface, but called reflectively (so it is optional): *void SlotRightClicked(int slot) - overrides the behavior of right clicking an item slot Creating an Interface To actually build the interface itself, you must spawn an instance of the InterfaceObj class. For NPCs, you set Config.npcInterface to the InterfaceObj object. The InterfaceObj class consists of these methods: *Constructor: public InterfaceObj(Interfaceable item, int slotCount, int buttonCount) - The constructor takes the Interfaceable object that handles callbacks, and integers for allocating space. *void SetLocation(Vector2 vect) - Used for Tiles - set the location of the tile here, so it knows to close the interface when you move a certain distance away. *int AddText(string text, int x, int y, bool clickable,float scale=1f) - Add a text button to the screen at the specified location. If clickable is true, it will call the ButtonClicked() method in the interfaceable object. *int AddItemSlot(int x, int y) - Adds an item slot to the specified location. Example (in the Examples mod): Config.npcInterface = new InterfaceObj(new EnchantInterface(), 3, 3); //Pass along this code instance, and the # of item slots you want to use Config.npcInterface.AddItemSlot(150,250); Config.npcInterface.AddItemSlot(230,250); Config.npcInterface.AddItemSlot(190,300); Config.npcInterface.AddText("Enchant:", 130, 230, false, 0.9f); Config.npcInterface.AddText("Rune:", 225, 230, false, 0.9f); Config.npcInterface.AddText("Result:", 140, 310, false,0.9f); Item For everything: *void Initialize() *void Save(BinaryWriter writer) - Saves data, for either the world or the player. Also used to transfer data in multiplayer. *void Load(BinaryReader reader, int version) - Loads data for the world or the player. Also used to transfer data in multiplayer. *void PlayerGrab(Player player, int playerID, int itemIndex) - Called when the item collides with the player. This is where health or mana crystals give the player health/mana, and normal items go into the player's inventory. Defining this method will override the default behavior for normal items. The itemIndex is the index into the Main.item[] array. For usable items (consumables, weapons): *void UseItem(Player player, int playerID) *bool CanUse(Player player, int playerID) - Return True if the item can be used, false otherwise. This opens up more possibilities, and is needed for things like boomerangs that have a limit to the amount that can be thrown. For weapons *void UseItemEffect(Player player, Rectangle rectangle) **Used to create a visual effect, such as fire particles on a flame sword *bool UseAmmo(Player p) - return true if you want it to use ammo, false otherwise. You could easily make a weapon not use ammo 33% of the time or not use ammo under certain conditions. For Armor/Accessories: *void Effects(Player player) **Used to add passive effects that are active while the item is equipped For Armor: *void SetBonus(Player player) **Define effects that are only active while all armor pieces from a set are equipped *void PlayerFrame(Player player) **Define visual effects for set bonuses For weapons, armor/accessories, buffs, and ModPlayer: *void DamageNPC(Player myPlayer,NPC npc, ref int damage, ref float knockback) **Called when an NPC is hit with the weapon. You can add buff effects here, or alter the damage and knockback. You can also use it to spawn items. *void DealtNPC(Player myPlayer, NPC npc, double damage) **Called after you damage an enemy, it lets you see how much damage was dealt and perform some action. *void DealtPlayer(Player myPlayer, double damage, NPC npc) - Called after the player takes damage from an NPC *DamagePVP(Player myPlayer, ref int damage, Player enemyPlayer) - PvP method that allows you to intercept the damage taken and modify it in some way. *DealtPVP(Player myPlayer, int damage, Player enemyPlayer) - PvP method that allows you to react to the total damage dealt to the enemy player. *void OnSpawn(Player player, int id) - called when the player respawns. *void FrameEffect(Player player) - Similar to the PlayerFrame() method, but it gets called for all items, buffs, etc and doesn't care about set bonuses. *bool PreDraw(Player player, SpriteBatch spriteBatch) - Called before DrawPlayer; return true to let it continue with DrawPlayer(), false otherwise. *void PostDraw(Player player, SpriteBatch spriteBatch) - called after DrawPlayer tConfig Custom Properties NPC *void Initialize() *void FindFrame(int currentFrame) - Handle custom animations here *void AI() - Handle AI *bool PreAI() - Called before AI(); return false if you don't want it to run the normal AI routine *void PostAI() - called after AI() *bool SpawnNPC(int x, int y, int playerID) - return true if you want the NPC to spawn. *void SetupShop(Chest chest) - Handle shop items for your Town NPC *string Chat() - Return the line of text you want the NPC to say *bool TownSpawn() - return true if you want the NPC to spawn as a Town NPC *void NPCLoot() - Handle death events and drop items *string SetName() - Required method to set the name of your Town NPC. *void DealtNPC(double damage, Player player) - Called after the NPC takes damage from a player or a player's projectile *void DamagePlayer(Player player, ref int damage) *void HitEffect(int hitDirection, double damage) - Used primarily for visual (dust) effects and gore when the NPC is hit or killed. *NPC Interface methods: **string ChatFuncName() - Return the text you click on to call the ChatFunc(). **void ChatFunc() - Perform some action when the text is clicked on. You can define an interface here, or maybe turn the NPC into Skeletron. **bool CanPlaceSlot(int slot, Item mouseItem) - return true if you want to let the player place / pick up an item in the specified slot. mouseItem is the item currently held by the mouse. **void PlaceSlot(int slot) - Perform some action after an item has been placed or taken from the specified slot **bool DropSlot(int slot) - Called when the interface is closed - return true if you want the item in the slot to be dropped, false otherwise. *bool PreDraw(SpriteBatch spriteBatch) - Called before the default drawing code; return true to execute the regular drawing code, otherwise return false. *void PostDraw(SpriteBatch spriteBatch) - Called after the default drawing code tConfig Custom Properties Buff There are separate methods for buffs on NPCs and buffs on the Player. *Called every 'tick': **void Effects(Player p, int buffType, int buffIndex) **void NPCEffects(NPC npc, int buffType, int buffIndex) *Called when the buff starts: **void EffectsStart(Player p, int buffType, int buffIndex) **void NPCEffectsStart(NPC npc, int buffType, int buffIndex) *Called when the buff ends: **void EffectsEnd(Player p, int buffType) **void NPCEffectsEnd(NPC npc, int buffType) *Used for saving/loading data: **void Save(BinaryWriter writer) **void Load(BinaryReader reader, int version) *Other: **void DamageNPC(Player myPlayer,NPC npc, ref int damage, ref float knockback) ***Called when an NPC is hit with the weapon. **void DamagePlayer(Player player, ref int damage, NPC npc) - Use to modify damage the player receives when hit by an NPC **void DealtPlayer(Player player, double damage, NPC npc) - Called after the player takes damage from an NPC **void DamagePVP(Player myPlayer, ref int damage, Player enemyPlayer) **void DealtPVP(Player myPlayer, int damage, Player enemyPlayer) Projectile *void Initialize() *void AI() *bool PreAI() - called before AI(); return true to execute AI(), false otherwise. *void PostAI() - called after AI() *void DamageNPC(NPC npc, ref int damage, ref float knockback) *void DealtNPC(NPC npc, double damage, Player player) *void Kill() **Here, decide what to do with the projectile is destroyed. You could create an explosion, for instance. *void DamagePVP(ref int damage, Player enemyPlayer) *void DealtPVP(double damage, Player enemyPlayer) *bool PreDraw(SpriteBatch spriteBatch) - Called before the default drawing code; return true to execute the regular drawing code, otherwise return false. *void PostDraw(SpriteBatch spriteBatch) - Called after the default drawing code tConfig Custom Properties Tile *void Initialize() - Called when the first tile of this type is placed, or when the world is loaded. *void UseTile(Player player, int x, int y) **Called when the player clicks on the tile *void PlaceTile(int x, int y) - Called when a tile is placed *void DestroyTile(int x, int y) - Called when a tile is destroyed - Deprecated *void KillTile(int x, int y, Player player) - Called when a tile is destroyed. *bool CanDestroyTile(int x, int y) - Return true if the tile can be destroyed, false otherwise. Useful for a chest, if you want it to be indestructible while it contains items. *void Save(BinaryWriter writer) - Called when the world is saved *void Load(BinaryReader reader, int version) - Called when the world is loaded *static void SaveGlobal(BinaryWriter writer) - Like Save(), but for static variables *static void LoadGlobal(BinaryReader reader, int version) - Like Load(), but for static variables *void hitWire(int x, int y) - called when a tile is activated by a wire *void UpdateFrame(int x, int y) *void Update(int x, int y) - called every tick *bool CheckTile(int x, int y) - Overrides the normal CheckTile method. Check the consistency of the tile types and tile frames. Return true if the check passes; false otherwise. ** Currently (tConfig 23.1) works backwards- False passes, true fails and destroys tile. *bool CheckPlaceTile(int x, int y) - Overrides the normal CheckPlaceTile method. Check the ground, ceiling, surrounding area, etc. to see if the tile can be placed. Return true if the check passes; false otherwise. *bool CanExplode(int x, int y, int projectileType) - Return true if the tile can be destroyed by an explosion, false otherwise. This only affects explosions from vanilla explosive projectiles, such as Bomb, Dynamite, Sticky Bomb, etc. In Global code file (Tile.cs): *void ModifyWorld() - Called after world generation, you can modify the world any way you want - put items in chests, modify tiles to add new ores, etc. tConfig Custom Properties Category:Classes